home *** CD-ROM | disk | FTP | other *** search
/ CD Exchange / CD Exchange - Volume 1.iso / graphics / utils / ham8-jpeg / source / display24.c < prev    next >
C/C++ Source or Header  |  1992-12-20  |  19KB  |  948 lines

  1. /*
  2.  * display24.c Michael Saunby    M.Saunby@reading.ac.uk
  3.  *
  4.  * Release 1.1
  5.  *
  6.  * Display 24 bit RGB data using the Albert HAM8 screen.
  7.  */
  8.  
  9. #include <exec/memory.h>
  10. #include <libraries/dos.h>
  11. #include <libraries/dosextens.h>
  12. #include <intuition/intuition.h>
  13. #include <graphics/gfxbase.h>
  14. #include <graphics/displayinfo.h>
  15. #include <intuition/screens.h>
  16.  
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/graphics_protos.h>
  20.  
  21. #include <stdlib.h>
  22. #include "display24.h"
  23.  
  24. /* 
  25.  * Change USE_STD_COLOURS to 0 for ham only.  Faster but not as sharp. 
  26.  * More code could be disabled for greater speed.
  27.  */
  28. #define USE_STD_COLOURS 1
  29.  
  30. typedef UBYTE std_pal_type;
  31. static ULONG red_dist[9], green_dist[9], blue_dist[9];
  32. static UWORD standard_pens[48];
  33.  
  34.  
  35. /*
  36.  * The following defines set the standard palette colours.
  37.  * The __inline functions are used to compare these colours with the input
  38.  * colour.
  39.  *
  40.  * Greys
  41.  */
  42. #define STD_COLOUR_01 {0,0,0}
  43. static __inline ULONG 
  44. dist_fn_01 ()
  45. {
  46.   return (red_dist[0] + green_dist[0] + blue_dist[0]);
  47. }
  48.  
  49. #define STD_COLOUR_02 {32,32,32}
  50. static __inline ULONG 
  51. dist_fn_02 ()
  52. {
  53.   return (red_dist[1] + green_dist[1] + blue_dist[1]);
  54. }
  55.  
  56. #define STD_COLOUR_03 {64,64,64}
  57. static __inline ULONG 
  58. dist_fn_03 ()
  59. {
  60.   return (red_dist[2] + green_dist[2] + blue_dist[2]);
  61. }
  62.  
  63. #define STD_COLOUR_04 {96,96,96}
  64. static __inline ULONG 
  65. dist_fn_04 ()
  66. {
  67.   return (red_dist[3] + green_dist[3] + blue_dist[3]);
  68. }
  69.  
  70. #define STD_COLOUR_05 {128,128,128}
  71. static __inline ULONG 
  72. dist_fn_05 ()
  73. {
  74.   return (red_dist[4] + green_dist[4] + blue_dist[4]);
  75. }
  76.  
  77. #define STD_COLOUR_06 {160,160,160}
  78. static __inline ULONG 
  79. dist_fn_06 ()
  80. {
  81.   return (red_dist[5] + green_dist[5] + blue_dist[5]);
  82. }
  83.  
  84. #define STD_COLOUR_07 {192,192,192}
  85. static __inline ULONG 
  86. dist_fn_07 ()
  87. {
  88.   return (red_dist[6] + green_dist[6] + blue_dist[6]);
  89. }
  90.  
  91. #define STD_COLOUR_08 {224,224,224}
  92. static __inline ULONG 
  93. dist_fn_08 ()
  94. {
  95.   return (red_dist[7] + green_dist[7] + blue_dist[7]);
  96. }
  97.  
  98. #define STD_COLOUR_09 {255,255,255}
  99. static __inline ULONG 
  100. dist_fn_09 ()
  101. {
  102.   return (red_dist[8] + green_dist[8] + blue_dist[8]);
  103. }
  104.  
  105. /*
  106.  * reds
  107.  */
  108. #define STD_COLOUR_10 {64,0,0}
  109. static __inline ULONG 
  110. dist_fn_10 ()
  111. {
  112.   return (red_dist[2] + green_dist[0] + blue_dist[0]);
  113. }
  114.  
  115. #define STD_COLOUR_11 {128,0,0}
  116. static __inline ULONG 
  117. dist_fn_11 ()
  118. {
  119.   return (red_dist[4] + green_dist[0] + blue_dist[0]);
  120. }
  121.  
  122. #define STD_COLOUR_12 {192,0,0}
  123. static __inline ULONG 
  124. dist_fn_12 ()
  125. {
  126.   return (red_dist[6] + green_dist[0] + blue_dist[0]);
  127. }
  128.  
  129. #define STD_COLOUR_13 {255,0,0}
  130. static __inline ULONG 
  131. dist_fn_13 ()
  132. {
  133.   return (red_dist[8] + green_dist[0] + blue_dist[0]);
  134. }
  135.  
  136. /*
  137.  * greens
  138.  */
  139. #define STD_COLOUR_14 {0,64,0}
  140. static __inline ULONG 
  141. dist_fn_14 ()
  142. {
  143.   return (red_dist[0] + green_dist[2] + blue_dist[0]);
  144. }
  145.  
  146. #define STD_COLOUR_15 {0,128,0}
  147. static __inline ULONG 
  148. dist_fn_15 ()
  149. {
  150.   return (red_dist[0] + green_dist[4] + blue_dist[0]);
  151. }
  152.  
  153. #define STD_COLOUR_16 {0,192,0}
  154. static __inline ULONG 
  155. dist_fn_16 ()
  156. {
  157.   return (red_dist[0] + green_dist[6] + blue_dist[0]);
  158. }
  159.  
  160. #define STD_COLOUR_17 {0,255,0}
  161. static __inline ULONG 
  162. dist_fn_17 ()
  163. {
  164.   return (red_dist[0] + green_dist[8] + blue_dist[0]);
  165. }
  166.  
  167. /*
  168.  * blues
  169.  */
  170. #define STD_COLOUR_18 {0,0,64}
  171. static __inline ULONG 
  172. dist_fn_18 ()
  173. {
  174.   return (red_dist[0] + green_dist[0] + blue_dist[2]);
  175. }
  176.  
  177. #define STD_COLOUR_19 {0,0,128}
  178. static __inline ULONG 
  179. dist_fn_19 ()
  180. {
  181.   return (red_dist[0] + green_dist[0] + blue_dist[4]);
  182. }
  183.  
  184. #define STD_COLOUR_20 {0,0,192}
  185. static __inline ULONG 
  186. dist_fn_20 ()
  187. {
  188.   return (red_dist[0] + green_dist[0] + blue_dist[6]);
  189. }
  190.  
  191. #define STD_COLOUR_21 {0,0,255}
  192. static __inline ULONG 
  193. dist_fn_21 ()
  194. {
  195.   return (red_dist[0] + green_dist[0] + blue_dist[8]);
  196. }
  197.  
  198. /*
  199.  * red-greens
  200.  */
  201. #define STD_COLOUR_22 {255,64,0}
  202. static __inline ULONG 
  203. dist_fn_22 ()
  204. {
  205.   return (red_dist[8] + green_dist[2] + blue_dist[0]);
  206. }
  207.  
  208. #define STD_COLOUR_23 {255,128,0}
  209. static __inline ULONG 
  210. dist_fn_23 ()
  211. {
  212.   return (red_dist[8] + green_dist[4] + blue_dist[0]);
  213. }
  214.  
  215. #define STD_COLOUR_24 {255,192,0}
  216. static __inline ULONG 
  217. dist_fn_24 ()
  218. {
  219.   return (red_dist[8] + green_dist[6] + blue_dist[0]);
  220. }
  221.  
  222. #define STD_COLOUR_25 {255,255,0}
  223. static __inline ULONG 
  224. dist_fn_25 ()
  225. {
  226.   return (red_dist[8] + green_dist[8] + blue_dist[0]);
  227. }
  228.  
  229. /*
  230.  * red-blues
  231.  */
  232. #define STD_COLOUR_26 {255,0,64}
  233. static __inline ULONG 
  234. dist_fn_26 ()
  235. {
  236.   return (red_dist[8] + green_dist[0] + blue_dist[2]);
  237. }
  238.  
  239. #define STD_COLOUR_27 {255,0,128}
  240. static __inline ULONG 
  241. dist_fn_27 ()
  242. {
  243.   return (red_dist[8] + green_dist[0] + blue_dist[4]);
  244. }
  245.  
  246. #define STD_COLOUR_28 {255,0,192}
  247. static __inline ULONG 
  248. dist_fn_28 ()
  249. {
  250.   return (red_dist[8] + green_dist[0] + blue_dist[6]);
  251. }
  252.  
  253. #define STD_COLOUR_29 {255,0,255}
  254. static __inline ULONG 
  255. dist_fn_29 ()
  256. {
  257.   return (red_dist[8] + green_dist[0] + blue_dist[8]);
  258. }
  259.  
  260. /*
  261.  * green-reds
  262.  */
  263. #define STD_COLOUR_30 {64,255,0}
  264. static __inline ULONG 
  265. dist_fn_30 ()
  266. {
  267.   return (red_dist[2] + green_dist[8] + blue_dist[0]);
  268. }
  269.  
  270. #define STD_COLOUR_31 {128,255,0}
  271. static __inline ULONG 
  272. dist_fn_31 ()
  273. {
  274.   return (red_dist[4] + green_dist[8] + blue_dist[0]);
  275. }
  276.  
  277. #define STD_COLOUR_32 {192,255,0}
  278. static __inline ULONG 
  279. dist_fn_32 ()
  280. {
  281.   return (red_dist[6] + green_dist[8] + blue_dist[0]);
  282. }
  283.  
  284. /*
  285.  * green-blues
  286.  */
  287. #define STD_COLOUR_33 {0,255,64}
  288. static __inline ULONG 
  289. dist_fn_33 ()
  290. {
  291.   return (red_dist[0] + green_dist[8] + blue_dist[2]);
  292. }
  293.  
  294. #define STD_COLOUR_34 {0,255,128}
  295. static __inline ULONG 
  296. dist_fn_34 ()
  297. {
  298.   return (red_dist[0] + green_dist[8] + blue_dist[4]);
  299. }
  300.  
  301. #define STD_COLOUR_35 {0,255,192}
  302. static __inline ULONG 
  303. dist_fn_35 ()
  304. {
  305.   return (red_dist[0] + green_dist[8] + blue_dist[6]);
  306. }
  307.  
  308. #define STD_COLOUR_36 {0,255,255}
  309. static __inline ULONG 
  310. dist_fn_36 ()
  311. {
  312.   return (red_dist[0] + green_dist[8] + blue_dist[8]);
  313. }
  314.  
  315. /*
  316.  * blue-reds
  317.  */
  318. #define STD_COLOUR_37 {64,255,0}
  319. static __inline ULONG 
  320. dist_fn_37 ()
  321. {
  322.   return (red_dist[2] + green_dist[8] + blue_dist[0]);
  323. }
  324.  
  325. #define STD_COLOUR_38 {128,255,0}
  326. static __inline ULONG 
  327. dist_fn_38 ()
  328. {
  329.   return (red_dist[4] + green_dist[8] + blue_dist[0]);
  330. }
  331.  
  332. #define STD_COLOUR_39 {192,255,0}
  333. static __inline ULONG 
  334. dist_fn_39 ()
  335. {
  336.   return (red_dist[6] + green_dist[8] + blue_dist[0]);
  337. }
  338.  
  339. /*
  340.  * blue-greens
  341.  */
  342. #define STD_COLOUR_40 {0,64,255}
  343. static __inline ULONG 
  344. dist_fn_40 ()
  345. {
  346.   return (red_dist[0] + green_dist[2] + blue_dist[8]);
  347. }
  348.  
  349. #define STD_COLOUR_41 {0,128,255}
  350. static __inline ULONG 
  351. dist_fn_41 ()
  352. {
  353.   return (red_dist[0] + green_dist[4] + blue_dist[8]);
  354. }
  355.  
  356. #define STD_COLOUR_42 {0,192,255}
  357. static __inline ULONG 
  358. dist_fn_42 ()
  359. {
  360.   return (red_dist[0] + green_dist[6] + blue_dist[8]);
  361. }
  362.  
  363. /*
  364.  * red green blue
  365.  */
  366. #define STD_COLOUR_43 {255,255,64}
  367. static __inline ULONG 
  368. dist_fn_43 ()
  369. {
  370.   return (red_dist[8] + green_dist[8] + blue_dist[2]);
  371. }
  372.  
  373. #define STD_COLOUR_44 {255,255,128}
  374. static __inline ULONG 
  375. dist_fn_44 ()
  376. {
  377.   return (red_dist[8] + green_dist[8] + blue_dist[4]);
  378. }
  379.  
  380. /*
  381.  * red blue green
  382.  */
  383. #define STD_COLOUR_45 {255,64,255}
  384. static __inline ULONG 
  385. dist_fn_45 ()
  386. {
  387.   return (red_dist[8] + green_dist[2] + blue_dist[8]);
  388. }
  389.  
  390. #define STD_COLOUR_46 {255,128,255}
  391. static __inline ULONG 
  392. dist_fn_46 ()
  393. {
  394.   return (red_dist[8] + green_dist[4] + blue_dist[8]);
  395. }
  396.  
  397. /*
  398.  * green blue red
  399. */
  400. #define STD_COLOUR_47 {64,255,255}
  401. static __inline ULONG 
  402. dist_fn_47 ()
  403. {
  404.   return (red_dist[2] + green_dist[8] + blue_dist[8]);
  405. }
  406.  
  407. #define STD_COLOUR_48 {128,255,255}
  408. static __inline ULONG 
  409. dist_fn_48 ()
  410. {
  411.   return (red_dist[4] + green_dist[8] + blue_dist[8]);
  412. }
  413.  
  414.  
  415. static std_pal_type standard_palette[48][3] =
  416. {
  417.   STD_COLOUR_01, STD_COLOUR_02, STD_COLOUR_03, STD_COLOUR_04, STD_COLOUR_05,
  418.   STD_COLOUR_06, STD_COLOUR_07, STD_COLOUR_08, STD_COLOUR_09, STD_COLOUR_10,
  419.   STD_COLOUR_11, STD_COLOUR_12, STD_COLOUR_13, STD_COLOUR_14, STD_COLOUR_15,
  420.   STD_COLOUR_16, STD_COLOUR_17, STD_COLOUR_18, STD_COLOUR_19, STD_COLOUR_20,
  421.   STD_COLOUR_21, STD_COLOUR_22, STD_COLOUR_23, STD_COLOUR_24, STD_COLOUR_25,
  422.   STD_COLOUR_26, STD_COLOUR_27, STD_COLOUR_28, STD_COLOUR_29, STD_COLOUR_30,
  423.   STD_COLOUR_31, STD_COLOUR_32, STD_COLOUR_33, STD_COLOUR_34, STD_COLOUR_35,
  424.   STD_COLOUR_36, STD_COLOUR_37, STD_COLOUR_38, STD_COLOUR_39, STD_COLOUR_40,
  425.   STD_COLOUR_41, STD_COLOUR_42, STD_COLOUR_43, STD_COLOUR_44, STD_COLOUR_45,
  426.